package volt_energy;

import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import volt_energy.Base.BaseTest;

import com.voltmao.energy.Dao.ApnCodeDAO;
import com.voltmao.energy.Dao.MeterInfo;
import com.voltmao.energy.Dao.VoltModule;
import com.voltmao.energy.Event.MyEventBus;
import com.voltmao.energy.Event.TestEventListener;
import com.voltmao.energy.Mapper.ApnCodeMapper;
import com.voltmao.energy.Mapper.MeterInfoMapper;
import com.voltmao.energy.Service.ApnCodeService;
import com.voltmao.energy.Service.MeterInfoService;
import com.voltmao.energy.Service.VoltModuleService;

public class test extends BaseTest{
	@Resource
	private ApnCodeService apnService; 
	@Resource
	private MeterInfoService meterService; 
	
	@Resource
	private VoltModuleService moduleService; 
	
//	@Test
	public void testBeans(){
//		VoltModule module = new VoltModule();
//		module.setModuleName("模块一");
//		moduleService.addModule(module);
//		VoltModule lists = moduleService.getModuleByPk(1);
		System.out.println(moduleService.getModuleByPk(1));
	}
	
	//@Test
	public void testEventBus() {
		MyEventBus.register(new TestEventListener());
		MyEventBus.post("zl is cool");
	}
	
	@Test
	public void testSqlServer(){
		 String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // 加载JDBC驱动
		 String dbURL = "jdbc:sqlserver://db.energydb.cn:1433;databaseName=voltcat_data"; 
		    
         String userName = "voltcat"; // 用户名
         String userPwd = "vot@2018"; // 密码
         
         try {
             // 加载SQLSERVER JDBC驱动程序
             Class.forName(driverName);
             //建立数据库连接
             Connection connect = DriverManager.getConnection(dbURL, userName,userPwd);
             Statement stmt = connect.createStatement();
             ResultSet rs = stmt.executeQuery("select * from c_current;");
             while (rs.next()) {
                 System.out.println(rs.getString("occur")+"  ||   "+ rs.getString("area"));
             }
         } catch (ClassNotFoundException e) {
             System.out.print("Error loading SQLServer Driver!");
             e.printStackTrace();
         } catch (Exception e) {
             System.out.print("get data error!");
             e.printStackTrace();
         }
     }
	
//	@Test
	public void testSql(){
		List<ApnCodeDAO> lists = apnService.getAll();
		System.out.println(lists);
		MeterInfo meter = meterService.getByPK(1L);
		System.out.println(meter);
	}

}
